﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

using SuperMap.Data;
using SuperMap.Mapping;
using SuperMap.UI;

namespace Demo
{
    public partial class frmView : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        public frmView()
        {
            InitializeComponent();
        }



        public void NewProject()
        {
            mapControl1.Map.Close();
            workspace1.Close();


            WorkspaceConnectionInfo connInfo = new WorkspaceConnectionInfo();
            workspace1.Create(connInfo);
            bool b = this.workspace1.Create(connInfo);
            if (b == false)
            {
            }
            mapControl1.Map.Workspace = workspace1;

            //创建数据源
            DatasourceConnectionInfo dsConnInfo = new DatasourceConnectionInfo();
            Datasource dataSource = workspace1.Datasources.Create(dsConnInfo);

            //创建数据集
            DatasetVectorInfo vectorInfo = new DatasetVectorInfo("LineSource", DatasetType.Line);            
            DatasetVector vectorDataset = dataSource.Datasets.Create(vectorInfo);

            Point2Ds pts = new Point2Ds();
            pts.Add(new Point2D(0, 0));
            pts.Add(new Point2D(100, 100));
            GeoLine line = new GeoLine(pts);
            Recordset record = vectorDataset.GetRecordset(false, CursorType.Dynamic);
            record.AddNew(line);


            pts = new Point2Ds();
            pts.Add(new Point2D(10, 10));
            pts.Add(new Point2D(100, -100));
            line = new GeoLine(pts);
            record.AddNew(line);

            vectorDataset.Append(record);
           

            //创建自定义map
            Map map = new Map(workspace1);
            map.Name = "map";           
            Layer layer = map.Layers.Add(vectorDataset,true);
            layer.Caption = "线源";
            

            //layer. = "LineSource";
            workspace1.Maps.Add(map.Name, map.ToXML());
            mapControl1.Map.Open(workspace1.Maps[0]);
       
            //workspace1.Save();
            //workspace1.SaveAs(connInfo);

            //mapControl1.Map.Close();
            //workspace1.Close();

        }



        #region 地图操做


        public void Pan()
        {
            this.mapControl1.Action = SuperMap.UI.Action.Pan;
        }

        public void ZoomToMax()
        {
            this.mapControl1.Map.ViewEntire();
        }

        public void SelectShape()
        {
            this.mapControl1.Action = SuperMap.UI.Action.Select2;            
        }

        public void AddLine(string layername)
        {
            this.mapControl1.Action = SuperMap.UI.Action.Null;
            this.mapControl1.ActiveEditableLayer = this.mapControl1.Map.Layers[layername];
            this.mapControl1.Action = SuperMap.UI.Action.CreateFreePolyline;
            
        }

        



        #endregion






    }
}
